// Copyright (c) 2022 CHANGLEI. All rights reserved.

import 'package:aircraft_war/foundation/sounds.dart';
import 'package:bloc/bloc.dart';

const _max = 1 << 32;

/// Created by changlei on 2022/5/19.
///
/// 增强子弹
class GameBulletCubit extends Cubit<int> {
  /// 生命值
  GameBulletCubit() : super(0);

  /// 是否超过最大值
  bool get isMax => state >= _max;

  /// 是否最小
  bool get isMin => state <= 0;

  /// 命中
  void supply() {
    if (state < _max) {
      emit(state + 150);
      Sounds.getBulletSupply();
    }
  }

  /// 命中
  bool consume() {
    if (state > 0) {
      emit(state - 1);
    }
    return isMin;
  }

  /// 重置
  void reset() {
    emit(0);
  }
}
